<?php

function smarty_function_getcategory2_by_topic_id($params, &$smarty) {
    //Get value from page
    $id = $params['topic_id'];
    if($id){
      //Query data

    $pntables = pnDBGetTables();
    $tpc_table  = $pntables['innoforum_topics'];
    $tpc_column = $pntables['innoforum_topics_column'];
		
    $cty_table  = $pntables['innoforum_category'];
    $cty_column = $pntables['innoforum_category_column'];

      $sql = "SELECT
                $cty_table.$cty_column[id] as category_id,
                $cty_table.$cty_column[name] as category_name
              FROM 
                $tpc_table ,
                $cty_table
              WHERE
                $tpc_table.$tpc_column[id] = $id
              AND
                $cty_table.$cty_column[id] = $tpc_table.$tpc_column[category_id]
              ";

      $column = array("category_id","category_name");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);
      //$category = $objectArray['0']['category_name'];
      //$subcategory = $objectArray['0']['subcategory_name'];
			if(isset($objectArray)){
				$smarty->assign("category_id", $objectArray['0']['category_id']);
				$smarty->assign("category_name", $objectArray['0']['category_name']);
			}else{
				$smarty->assign("category_id", NULL);
				$smarty->assign("category_name", NULL);
			}			
			
    }


}